package ar.com.drconta.ganancias.views.code;

import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

import ar.com.drconta.ganancias.views.vogella.Category;
import ar.com.drconta.ganancias.views.vogella.TodoLabelProvider;
 

 
public class MyTreeLabelProvider implements ILabelProvider {
 
	  private static final Image FOLDER = getImage("folder.gif");
	  private static final Image FILE = getImage("file.gif");
	  //images/eview.gif
	  @Override
	  public Image getImage(Object element) {
	    if (element instanceof Category) {
	      return FOLDER;
	    }
	    return FILE;
	  }

	  // Helper Method to load the images
	  private static Image getImage(String file) {
	    Bundle bundle = FrameworkUtil.getBundle(TodoLabelProvider.class);
	    URL url = FileLocator.find(bundle, new Path("icons/sample.gif"), null);
	    System.out.println(url);
	    ImageDescriptor image = ImageDescriptor.createFromURL(url);
	    return image.createImage();

	  }
	  
        @Override
 
        public String getText(Object obj) {
 
                String result = null;
 
                if(obj instanceof GameWorld) {
 
                        result = "GameWorld";
 
                } else if (obj instanceof Team) {
 
                        result = "Team";
 
                } else if (obj instanceof Person) {
 
                        Person p = ((Person) obj);
 
                        result = p.getName() + ":" + p.getId();
 
                }
 
                return result;
 
        }
 

 
        @Override
 
        public void addListener(ILabelProviderListener arg0) {
 
        }
 

 
        @Override
 
        public void dispose() {
 
        }
 

 
        @Override
 
        public boolean isLabelProperty(Object arg0, String arg1) {
 
                return false;
 
        }
 

 
        @Override
 
        public void removeListener(ILabelProviderListener arg0) {
 
        }
 

 

 
}
 
